package com.dementors.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.dementors.R;

/**
 * Created by Administrator on 2015/12/5 0005.
 */
public class MyPageView extends FrameLayout implements View.OnClickListener {
    private Context context;
    private ImageView ivPage;
    private TextView tvPage;
    private Button btnPage;
    public OnButtonCheckListener listener;

    public interface OnButtonCheckListener{
         void setOnButtonCheckListener();
    }
    public void setOnButtonCheckListener(OnButtonCheckListener listener){
        this.listener=listener;
    }
    public MyPageView(Context context) {
        this(context, null);
    }

    public MyPageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyPageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
        LayoutInflater.from(context).inflate(R.layout.mypageview, this, true);
        initViews();//初始化各个控件
        resigenerListener();//设置监听事件
    }

    private void resigenerListener() {
        btnPage.setOnClickListener(this);
    }

    private void initViews() {
        ivPage= (ImageView) findViewById(R.id.iv_page);
        tvPage= (TextView) findViewById(R.id.tv_page);
        btnPage= (Button) findViewById(R.id.btn_page);
    }

    @Override
    public void onClick(View v) {
        if (listener!=null){
            listener.setOnButtonCheckListener();
        }
    }

    public void setImage(int res){
        ivPage.setImageResource(res);
    }
    public void setText(String text){
        tvPage.setText(text);
    }

    public void setBtnText(String text){
        btnPage.setText(text);
    }
}
